<template>
<div class="announcement-management-add views-container">
  <div class="wlm-form">
    <div class="wlm-form-header">添加公告</div>
    <div class="wlm-form-content">
      <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
        <el-form-item label="公告名称" prop="title">
          <el-input v-model="formFormatData.formData.title" placeholder="请输入公告名称"></el-input>
        </el-form-item>
        <el-form-item label="作者">
          <el-input v-model="formFormatData.formData.author" placeholder="请输入作者名称"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="formFormatData.formData.is_show">
            <el-radio :label="1">显示</el-radio>
            <el-radio :label="0">隐藏</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="公告内容" prop="content">
          <ueditor :defaultMsg='defaultMsg' :config='{initialFrameWidth: null,initialFrameHeight: 350}' ref="ue"></ueditor>
        </el-form-item>
      </el-form>
    </div>
  </div>

  <div class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
    <el-button size="small" type="primary" @click="saveForm">保存</el-button>
    <router-link tag="span" to="/operation/announcementManagement">
      <el-button size="small">返回</el-button>
    </router-link>
  </div>
</div>
</template>

<script>
// import { userAdd } from '@/api/user'
import ueditor from '@/components/Ueditor/index'
import {
  messageSetAdd,
  messageOldDate
} from '@/api/setting'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'AnnouncementManagementAdd',
  components: {
    ueditor
  },
  directives: {

  },
  data() {
    return {
      defaultMsg: '',
      formFormatData: {
        key: 'announcement',
        api: {
          editForm: {
            api: messageOldDate
          },
          submitForm: messageSetAdd
        },
        formData: {
          title: '',
          is_show: 1,
          content: '',
          author: ''
        },
        rules: {
          title: [{
            required: true,
            message: '请输入公告名称',
            trigger: 'blur'
          }],
          content: [{
            required: true,
            message: '请输入公告内容',
            trigger: 'blur'
          }]
        }
      }
    }
  },
  methods: {
    saveForm() {
      this.ueditorChange()
      this.formFormatSubmit({ router: { type: 'replace', path: '/operation/announcementManagement', code: 1 }})
    },
    ueditorChange() {
      this.formFormatData.formData.content = this.$refs.ue.getUEContent('getContent')
    },
    formFormatCallBack(data, type) {
      if (type === 'editForm') {
        const { content = '' } = data
        this.defaultMsg = content
      }
    }
  }
}
</script>
